﻿using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using Microsoft.Practices.ServiceLocation;

namespace Sogeti.Guidelines.WCF.Hosting
{
    public class CommonServiceHostInstanceProvider : IInstanceProvider
    {
        public IServiceLocator Container { set; get; }
        public Type ServiceType { set; get; }

        public CommonServiceHostInstanceProvider() : this(null)
        {
        }


        public CommonServiceHostInstanceProvider(Type type)
        {
            ServiceType = type;
        }


        public object GetInstance(
            InstanceContext instanceContext,
            Message message)
        {
            return Container.GetInstance(ServiceType);
        }


        public object GetInstance(InstanceContext instanceContext)
        {
            return GetInstance(instanceContext, null);
        }


        public void ReleaseInstance(InstanceContext instanceContext, object instance)
        {
        }
    }
}